package me



class Util {


	static def cacheChartFile = [:]

	static def cacheChartDataSource = [:]

	static def cacheChartTheme = [:]

	static def cacheChartParam = [:]

	static def cacheChartAdapter = [:]

	static def cacheChartTableTheme = [:]

	static def chartOption = [:]	

	

	static def chartBand = [



	]

	static def optionTabs = [



	]

	static def chart = [
		[
			bandName:'新的图表',
			leaf:true
		]

	]


	static renderField(p) {
		def field = ""
		switch (p.optionType) {  
			case 'color':  
			    field = """
			    	{ 
			    		itemId:'${p.optionJson.replace(":","_")}',
			    		listeners:{
			    			change:function( obj, newValue, oldValue, eOpts) {
			    				if (chart1!=null) {
			    					parseJsonAttr(obj.itemId,'#'+newValue)
			    				}
			    				
			    			}
			    		},
			    		value:'${p.optionValue}',
			    		xtype:'colorfield',
			    		fieldLabel: '<font style=\"font-weight:bold\" color=blue>${p.optionName}</font> ${formatOptionId(p.optionId)}' 
			    	},
			    """
			   	break;       
			
			case 'boolean':   
			    field = """
			    	{ 
			    		itemId:'${p.optionJson.replace(":","_")}',
			    		listeners:{
			    			change:function( obj, newValue, oldValue, eOpts) {
			    				parseJsonAttr(obj.itemId,newValue)
			    				
			    			}
			    		},
			    		value:'${p.optionValue}',
			    		xtype:'checkboxfield',
			    		fieldLabel: '<font style=\"font-weight:bold\" color=blue>${p.optionName}</font> ${formatOptionId(p.optionId)}' 
			    	},
			    """
			    break;  
			case 'number':   
			    field = """
			    	{ 
			    		itemId:'${p.optionJson.replace(":","_")}',
			    		listeners:{
			    			change:function( obj, newValue, oldValue, eOpts) {
			    				parseJsonAttr(obj.itemId,newValue)
			    				
			    			}
			    		},
			    		value:'${p.optionValue}',
			    		xtype:'numberfield',
			    		fieldLabel: '<font style=\"font-weight:bold\" color=blue>${p.optionName}</font> ${formatOptionId(p.optionId)}' 
			    	},
			    """
			    break;  
			case 'string':  
			    field = """
			    	{ 
			    		itemId:'${p.optionJson.replace(":","_")}',
			    		listeners:{
			    			change:function( obj, newValue, oldValue, eOpts) {
			    				parseJsonAttr(obj.itemId,newValue)
			    			}
			    		},
			    		value:'${p.optionValue}',
			    		xtype:'textfield',
			    		fieldLabel: '<font style=\"font-weight:bold\" color=blue>${p.optionName}</font> ${formatOptionId(p.optionId)}' 
			    	},
			    """
			    break; 
			case '["Object"]':  
			    field = "{ xtype:'textfield',fieldLabel: '<font style=\"font-weight:bold\" color=blue>${p.optionName}</font> ${formatOptionId(p.optionId)}' },"
			    break;
			case '["Array"]':  
			    field = "{ xtype:'combobox',fieldLabel: '<font style=\"font-weight:bold\" color=blue>${p.optionName}</font> ${formatOptionId(p.optionId)}' },"
			    
			    break;     
			default:  
		    	field = "{ xtype:'combobox',fieldLabel: '<font style=\"font-weight:bold\" color=blue>${p.optionName}</font> ${formatOptionId(p.optionId)}' },"
		}  
		
		return field
	}

	static def formatOptionId(optionId) {
		def result = ""
		def temp = optionId.substring(0, 1).toUpperCase() + optionId.substring(1);  
		//println temp
		for( int i = 0 ; i<temp.length(); i++ ){            
            char a = temp.charAt(i);
            if (i==0) {
            	result = ""+a
            } else {
            	if( a>64 && a<91 ){              
	               	result += " "+a                
	            }else{                
	                result += ""+a          
	            } 
            }    
          

        }
        
      	if (optionId=="useUTC") {
      		result = "Use UTC"
      	}
		return result
	}

}
